#include <etcd/Client.hpp>
#include <etcd/KeepAlive.hpp>
#include <etcd/Response.hpp>
#include<iostream>

int main(int argc, char *argv[])
{
    std::string etcd_host = "http://127.0.0.1:2379";
    // 实例化一个etcd客户端
    etcd::Client client(etcd_host);
    // 获取一个租约保活对象--伴随着创建一个指定有效时长的租约
    auto keep_alive = client.leasekeepalive(3).get();
    // 获取租约id
    auto lease_id = keep_alive->Lease();
    // 向etcd添加数据
    auto response = client.put("/service/临时", "127.0.0.1:8888", lease_id).get(); // client操作返回为异步处理结果，需要通过get获取内容
    if (response.is_ok() == false)
    {
        std::cout << "新增数据失败，原因[" << response.error_message() << "]" << std::endl;
        return -1;
    }
    auto response1 = client.put("/service/长期", "127.0.0.1:8080").get(); 
    if (response1.is_ok() == false)
    {
        std::cout << "新增数据失败，原因[" << response1.error_message() << "]" << std::endl;
        return -1;
    }
    std::this_thread::sleep_for(std::chrono::seconds(10));
}
